package com.huluobo.a2206koltindouyin

import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.huluobo.a2206koltindouyin.adapter.CommonPagerAdapter
import com.huluobo.a2206koltindouyin.databinding.ActivityMainBinding
import com.huluobo.a2206koltindouyin.home.HomeFragment
import com.huluobo.a2206koltindouyin.message.MessageFragment
import com.huluobo.a2206koltindouyin.mine.MineFragment
import com.huluobo.a2206koltindouyin.startLive.StartLiveActivity
import com.huluobo.a2206koltindouyin.videos.VideoFragment
import com.huluobo.base.mvvm.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
//    private lateinit var commonPagerAdapter: CommonPagerAdapter
//    private val fragments = mutableListOf<Fragment>()
    override fun initData() {
//        fragments.clear()
//        fragments.add(HomeFragment())
//        fragments.add(VideoFragment())
//        fragments.add(MessageFragment())
//        fragments.add(MineFragment())
//
//        commonPagerAdapter = CommonPagerAdapter(this, fragments)
//        binding.mainVp2.adapter = commonPagerAdapter
    }

    override fun initView() {
//        binding.mainVp2.registerOnPageChangeCallback(object : OnPageChangeCallback() {
//            override fun onPageSelected(position: Int) {
//                super.onPageSelected(position)
//                when (position) {
//                    0 -> binding.mainNav.menu.getItem(0).isChecked = true
//                    1 -> binding.mainNav.menu.getItem(1).isChecked = true
//                    2 -> binding.mainNav.menu.getItem(3).isChecked = true
//                    3 -> binding.mainNav.menu.getItem(4).isChecked = true
//                }
//            }
//        })
//
//        binding.mainNav.setOnItemSelectedListener {
//            when (it.itemId) {
//                R.id.nav_home -> binding.mainVp2.currentItem = 0
//                R.id.nav_videos -> binding.mainVp2.currentItem = 1
//                R.id.nav_start_live -> startActivity(Intent(this, StartLiveActivity::class.java))
//                R.id.nav_message -> binding.mainVp2.currentItem = 2
//                R.id.nav_mine -> binding.mainVp2.currentItem = 3
//            }
//            true
//        }
        val navHostFragment = supportFragmentManager.findFragmentById(R.id.main_nav_host) as NavHostFragment
        val navController = navHostFragment.navController
        binding.mainNav.setupWithNavController(navController)
    }

    override fun onResume() {
        super.onResume()
//        binding.mainVp2.currentItem = 1
//        binding.mainNav.menu.getItem(1).isChecked = true
    }
}